package com.transcargo.geo;

import java.util.ArrayList;
import java.util.Iterator;

import com.transcargo.db.db;
import com.transcargo.db.dbException;

public class City {
	private String name = "";
	private int Country_id = -1;
	private int Region_id = -1;
	private int Id = -1;
	
	public City(int id, int country_id, db Db) throws dbException, GeoObjectNotFoundException
	{
		Country_id = country_id;
		Id = id;
		ArrayList<String[]> list = Db.execute("SELECT name,reg_id FROM cities WHERE city_id=" + Integer.toString(id) + " and country_id=" + Integer.toString(country_id));
		if (list != null) {
			Iterator<String[]> iter =list.iterator();
            if (iter == null || !iter.hasNext()) throw new GeoObjectNotFoundException(new com.transcargo.geo.Object(null, null, this));
			String[] ctr = iter.next();
			name = ctr[0];
			if (ctr[1].length() > 0) 
				Region_id = Integer.parseInt(ctr[1]);
			else Region_id = 0;
		} else throw new GeoObjectNotFoundException(new com.transcargo.geo.Object(null, null, this));
	}
	public String getName() {
		return name;
	}
    public int getId() {
        return Id;
    }
    public int getCountryId() {
        return Country_id;
    }
    public int getRegionId() {
        return Region_id;
    }
}
